import { Component, OnInit } from '@angular/core';
import { FormGroup,FormControl,FormArray } from '@angular/forms';
@Component({
  selector: 'app-reactive-forms',
  templateUrl: './reactive-forms.component.html',
  styleUrls: ['./reactive-forms.component.css']
})
export class ReactiveFormsComponent implements OnInit {

  //定义一个formgroup的对象俩面包含了一个dateRange的FormGroup的对象,这个dateRange中包含了两个formControl对象
  formGroup:FormGroup = new FormGroup({
    dateRange:new FormGroup({
      from:new FormControl,
      to:new FormControl
    }),
    email:new FormArray([
      new FormControl('1030@qq.com'),
      new FormControl('12345@qq.com')
    ])
  })

  constructor() { }

  ngOnInit() {
  }

/**
 * @description 页面提交函数
 */
  onSubmit(){
    console.log(this.formGroup.value);
  }

  /**
   * @description 新增email的的formContl
   */
  AddEmail(){
    let email = this.formGroup.get('email') as FormArray;
    email.push(new FormControl());
  }
}
